#ifndef _FOC_PID_H_
#define _FOC_PID_H_

#include "foc.h"

#define Lpf(a,a_last,lpf) (a * lpf + a_last * (1 - lpf))

typedef struct
{
    float kp;
    float ki;
    float err;
    float sum;
    float output;
    float maxout;
    float minout;
    float up;
		float ui;
	
	  float ref;
	  float fbk;
}CURRENT_PID_DEF;
extern CURRENT_PID_DEF current_q_pid;
extern CURRENT_PID_DEF current_d_pid;

typedef struct
{
	float Kp;
  float Ki;
  float Max_Output;
  float Min_Output;
  float I_Sum;
	float error;
	float output;
	float up;
	
	float ref;
	float fbk;
}SPEED_PID_DEF;
extern SPEED_PID_DEF speed_pid;


void speed_pid_init(SPEED_PID_DEF* speed_pid_temp, float motor_J, float motor_flux, unsigned int motor_Pole, unsigned int n);
void Speed_pid_c(SPEED_PID_DEF* speed_pid_temp);

void current_q_pid_Init(CURRENT_PID_DEF *current_temp, float motor_Ls, float motor_Rs, float Vbus);
void current_d_pid_Init(CURRENT_PID_DEF *current_temp, float motor_Ls, float motor_Rs, float Vbus);
void current_pid_Control(CURRENT_PID_DEF *current_temp);

#endif
